package com.fr.report.cellElement.core;

import com.fr.base.FCloneable;
import com.fr.base.FRContext;
import com.fr.base.Style;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.CellElement;
import com.fr.report.RWorkBook;
import com.fr.report.Report;
import com.fr.report.ResultWorkBook;
import com.fr.report.core.DynamicValueList;
import com.fr.report.core.PaintUtils;
import com.fr.report.core.ReportHelper;
import com.fr.report.painter.AbstractPainter;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ResultSubReport extends AbstractPainter
{
  public static final String XML_TAG = "ResultSubReport";
  private ResultWorkBook packee;

  public ResultSubReport()
  {
    this(new RWorkBook());
  }

  public ResultSubReport(ResultWorkBook paramResultWorkBook)
  {
    this.packee = paramResultWorkBook;
  }

  public ResultWorkBook getPackee()
  {
    return this.packee;
  }

  public void setPackee(ResultWorkBook paramResultWorkBook)
  {
    this.packee = paramResultWorkBook;
  }

  public void paint(Graphics paramGraphics, int paramInt1, int paramInt2, Style paramStyle)
  {
    Rectangle localRectangle1;
    CellElement localCellElement;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Report localReport = null;
    if (this.packee.getReportCount() > 0)
      localReport = this.packee.getReport(0);
    if (localReport == null)
      return;
    DynamicValueList localDynamicValueList1 = ReportHelper.getColumnWidthList(localReport);
    DynamicValueList localDynamicValueList2 = ReportHelper.getRowHeightList(localReport);
    ArrayList localArrayList1 = new ArrayList();
    ArrayList localArrayList2 = new ArrayList();
    Iterator localIterator = localReport.cellIterator();
    while (localIterator.hasNext())
    {
      localCellElement = (CellElement)localIterator.next();
      Rectangle localRectangle2 = new Rectangle(localCellElement.getColumn(), localCellElement.getRow(), localCellElement.getColumnSpan(), localCellElement.getRowSpan());
      localRectangle1 = new Rectangle(localDynamicValueList1.getRangeValue(0, localRectangle2.x), localDynamicValueList2.getRangeValue(0, localRectangle2.y), localDynamicValueList1.getRangeValue(localRectangle2.x, localRectangle2.x + localRectangle2.width), localDynamicValueList2.getRangeValue(localRectangle2.y, localRectangle2.y + localRectangle2.height));
      localArrayList1.add(localCellElement);
      localArrayList2.add(localRectangle1);
      localGraphics2D.translate(localRectangle1.x, localRectangle1.y);
      PaintUtils.paintBackground(localGraphics2D, localCellElement.getStyle(), localRectangle1.width, localRectangle1.height);
      PaintUtils.paintContent(localGraphics2D, localCellElement.getValue(), localCellElement.getStyle(), localRectangle1.width, localRectangle1.height);
      localGraphics2D.translate(-localRectangle1.x, -localRectangle1.y);
    }
    int i = 0;
    int j = localArrayList1.size();
    while (i < j)
    {
      localCellElement = (CellElement)localArrayList1.get(i);
      localRectangle1 = (Rectangle)localArrayList2.get(i);
      localGraphics2D.translate(localRectangle1.x, localRectangle1.y);
      PaintUtils.paintBorder(localGraphics2D, localCellElement.getStyle(), localRectangle1.width, localRectangle1.height);
      localGraphics2D.translate(-localRectangle1.x, -localRectangle1.y);
      ++i;
    }
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("packee"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("class")) != null)
          try
          {
            ResultWorkBook localResultWorkBook = null;
            Object localObject = Class.forName(str2).newInstance();
            if (localObject instanceof ResultWorkBook)
            {
              localResultWorkBook = (ResultWorkBook)localObject;
              setPackee(localResultWorkBook);
              paramXMLableReader.readXMLObject(localResultWorkBook);
            }
          }
          catch (Exception localException)
          {
            FRContext.getLogger().log(Level.WARNING, "Failed to read resultSubReport");
          }
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("packee").attr("class", this.packee.getClass().getName());
    this.packee.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ResultSubReport localResultSubReport = (ResultSubReport)super.clone();
    localResultSubReport.setPackee((ResultWorkBook)this.packee.clone());
    return localResultSubReport;
  }
}